<div class="box">
  <div class="box-header with-border">
    <h3 class="box-title">系统管理员表列表</h3>
    <div class="box-tools">
      <span onclick="list_add();" class="btn btn-info btn-sm">添加系统管理员表</span>
    </div>
  </div>
  <div class="box-body">
    <div>
      <form>
        <input type="text" style="width:200px" placeholder="输入名称" id="_s_name" name="_s_name" />
        <button type="button" class="btn btn-success btn-sm" onclick="reload_table();"><i class="Hui-iconfont">&#xe665;</i> 查找</button>
        <button type="reset" class="btn btn-sm" ><i class="Hui-iconfont">&#xe68f;</i> 重置</button>
      </form>
    </div>
    
    <div class="row">
      <div class="col-sm-10">
        <a href="javascript:;" onclick="list_del()" class="btn btn-danger btn-sm"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
      </div>
      <div class="col-sm-2">
        <select class="form-control" onchange="list_changeSize(this.value)">
          <option value="10">10</option>
          <option value="25">25</option>
          <option value="50">50</option>
          <option value="100">100</option>
        </select>
      </div>
    </div>
    
    <table id="table_list" class="table table-bordered table-striped">
      <thead>
        <tr class="text-c">
          <th width="10"><span><input type="checkbox" name="" value="" onclick="checkAll()"/></span></th>
          <th width="30">ID</th>
          
          <th>登录名</th>
          <th>密码</th>
          <th>真实姓名</th>
          <th>sex</th>
          <th>邮箱</th>
          <th>电话</th>
          <th>手机</th>
          <th>用户类型</th>
          <th>用户头像</th>
          <th>最后登陆IP</th>
          <th>最后登陆时间</th>
          <th>是否可登录</th>
          
          <th width="142px">操作</th>
        </tr>
      </thead>
      <tbody></tbody>
    </table>
    
  </div>
</div>

<script type="text/javascript">
var _table;
function reload_table(){
	if(_table){
		_table.draw();
	}else{
		alert("没有表格");
	}
}
function list_add(){
	var params = "";
	HtmlRender('${BASE}/admin/sys/SysAdmin/add'+params);
}
function list_del(id){
	var select_ids = "";
	if(id){
		select_ids=id;
	}else{
	    $("input[name='table_checkbox_id']:checked").each(function(){
	    	select_ids+=$(this).val()+",";   
	    });
	    if(""==select_ids){
	    	layer.msg('请先选择要删除的数据！', {icon: 3,offset: '45px'});
	    	return false;
	    }
	}
	layer.confirm('确认删除所选记录?', {icon: 3, title:'警告'}, function(index){	    
	    layer.close(index);
	    layer.load(1, {shade: [0.3,'#fff']});
	    $.post("${BASE}/admin/sys/SysAdmin/delete",{ids:select_ids},function(jsondata){
			layer.closeAll('loading');
			if( jsondata.code == "001" ){
				layer.msg(jsondata.msg, {icon: 6,offset: '45px'});
				reload_table();
			}else{
				layer.msg(jsondata.msg, {icon: 5,offset: '45px'});
			alert("XX");
			}
	    },"json");
	});
}
function list_edit(id){
    HtmlRender("${BASE}/admin/sys/SysAdmin/edit",{id:id});
}
function list_show(id){
	$.post("${BASE}/admin/sys/SysAdmin/show",{id:id}, function(str){
		layer.open({
			type: 1,
			shadeClose:true,
			title :'系统管理员表信息',
			area: ['800px', '500px'],
			content: str
		});
	});
}
function list_changeSize(size){
	if(_table){
		_table.page.len( size ).draw();
	}else{
		alert("没有表格");
	}
}
function checkAll(){
	$("#table_list").find("tr > td:first-child input:checkbox").prop("checked",$("table thead th input:checkbox").prop("checked"));
}
$(function(){
	_table = $("#table_list").DataTable({
		"fixedColumns": {
			"leftColumns": 1,
			"rightColumns": 1
		},
		"language": {
	        "url": '${STATIC}/lib/datatables/Chinese.json'
	    },
		"lengthChange":false,
		"autoWidth": true,
		"scrollX": true,
		"ordering":false,
		"searching":false,
		"serverSide":true,
		"ajax": {
		    "url": "${BASE}/admin/sys/SysAdmin/list",
		    "type": "POST",
		    "data": function ( d ) {
		        d._s_name = $('#_s_name').val();
	        }
		},
        "columns": [
            { "data": "id","class":"text-c",
              "render": function(data, type, row) {
            	  return '<input type="checkbox" name="table_checkbox_id" value="' + data + '" title="' + data + '" id="checkbox" />';
               }
            },
            { "data": "id" },
            
            { "data": "loginName","defaultContent":"" },
            { "data": "password","defaultContent":"" },
            { "data": "realName","defaultContent":"" },
            { "data": "sex","defaultContent":"" },
            { "data": "email","defaultContent":"" },
            { "data": "phone","defaultContent":"" },
            { "data": "mobile","defaultContent":"" },
            { "data": "userType","defaultContent":"" },
            { "data": "photo","defaultContent":"" },
            { "data": "loginIp","defaultContent":"" },
            { "data": "loginDate","defaultContent":"" },
            { "data": "loginFlag","defaultContent":"" },
            
            { "data": "id","class":"text-c",
              "render": function(data, type, row) {
            	  return '<a class="btn btn-info btn-xs" href="javascript:;" title="编辑" onclick="list_edit(\''+data+'\')"><i class="Hui-iconfont">&#xe6df;</i> 编辑</a>&nbsp;'
            	  		+'<a class="btn btn-danger btn-xs" href="javascript:;" title="删除" onclick="list_del(\''+data+'\')"><i class="Hui-iconfont">&#xe6e2;</i> 删除</a>&nbsp;'
            	  		+'<a class="btn btn-success btn-xs" href="javascript:;" title="查看" onclick="list_show(\''+data+'\')"><i class="Hui-iconfont">&#xe616;</i> 查看</a>';
               }
            }
        ]
	});
})
</script>